#include "OLDialogTitle.h"
#include "OLPixmapWidget.h"
#include "OLAppTemplateDefs.h"
#include "OLButton.h"

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QPainter>

OLDialogTitle::OLDialogTitle(const QPixmap& icon, const QString& title, QWidget *parent) :
    QWidget(parent)
{
    QHBoxLayout* layout = new QHBoxLayout();
    layout->setContentsMargins(0,0,0,0);
    layout->setSpacing(5);

    if( !icon.isNull() ) {
        OLPixmapWidget* iconWgt = new OLPixmapWidget(icon, this);
        iconWgt->resize(FINGER_SIZE-10, FINGER_SIZE-10);
        layout->addWidget(iconWgt);
    }

    QLabel* dlgTitle = new QLabel(title, this);
    dlgTitle->setAlignment(Qt::AlignVCenter);
    dlgTitle->setFixedHeight(FINGER_SIZE-10);
    layout->addWidget(dlgTitle);

    OLButton* closeBtn = new OLButton(this);
    closeBtn->iconButton(ButtonIcons(QPixmap(":/icons/close_off"), QPixmap(":/icons/close_on")));
    closeBtn->setFixedSize(FINGER_SIZE, FINGER_SIZE);
    connect(closeBtn, SIGNAL(clicked()), SIGNAL(dismissDialog()));
    layout->addWidget(closeBtn);

    setLayout(layout);
}

void OLDialogTitle::paintEvent(QPaintEvent* e)
{
    QPainter p(this);

    // draw background
    p.setPen(OLStyles::buttonHighlightBorder());
    p.setBrush(Qt::NoBrush);

    //p.drawLine(0, 0, width(), 0);
    p.drawLine(0, height()-1, width(), height()-1);
    //p.drawRoundedRect(rect().adjusted(0,0,-1,-1), 5, 5);
}

